package com.dkm.orproject.utils.jwt;

import com.dkm.orproject.dkmoa.domain.OaPersonnel;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

/**
 * @PROJECT_NAME: orproject
 * @DESCRIPTION:
 * @USER: 周佳佳
 * @DATE: 2020/7/23 16:12
 */
public class JWTVerifier {
    public static Boolean isVerify(String token, OaPersonnel user) {
        //签名秘钥，和生成的签名的秘钥一模一样

        if (user == null) {
            throw new RuntimeException("token没有,请重新登录");
        }
        //得到DefaultJwtParser
        Claims claims = Jwts.parser()
                //设置签名的秘钥
                .setSigningKey(user.getPkPersonnelId().toString())
                //设置需要解析的jwt
                .parseClaimsJws(token).getBody();

        String id=claims.get("id").toString();

        if (id.equals(user.getPkPersonnelId().toString())) {
            return true;
        }
        return false;
    }
}
